+function ($) { 
    var open = function (_target) {
        $target = $(_target);
        var str="";
        var marginRt = window.screen.width - $('body').width();//document.documentElement.clientWidth;
        $("html").addClass("modal-open");
        var marginRt1 = window.screen.width - $('body').width();//document.documentElement.clientWidth;
        $(document.body).css("margin-right", marginRt - marginRt1 + 'px');
        //if (marginRt < 20) //忽略有左侧插件栏的浏览器
        //    $(document.body).css("margin-right", 17 + 'px');

        /*  内容最大高度,窗口高度－上下30px，头尾高度 */
        var max_height = $(window).height()- 60 - 60 - 50;
        var $modal_body = $target.find(".modal-body");
        if ($modal_body.length>0){
            $modal_body.css("max-height",max_height + "px");
        }

        $target.show();
        str = '<div class="modal-backdrop" style="height:100%;min-height:' + $target[0].scrollHeight + 'px;"></div>';
        $target.prepend(str);
        var now_width = $target.find(".modal-dialog").width();
        $target.find(".modal-dialog").css("margin-left", - now_width / 2 + "px");
        $target.find('.modal-content').addClass("from-below");
        setTimeout(function () { $target.find(".modal-content").addClass("effeckt-show"); }, 300);
    };

    var task_open = 0;
    var open_task = function (_target) {

        $target = $(_target);

        //console.log("document height:" + $(document).height());
        var aa = $target.find(".modal-body:first");
        //console.log("modal-body top:" + $target.find(".modal-body:first").offsetTop);
        var height = $(document).height() - 60 - 60 - 22;
        //console.log("modal-body height:" + height);

        $target.find(".modal-body").css("height", height + "px");
        /*
        if ($("#project-member-list").length>0){
            left -= $("#project-member-list").width()+38;
        }
        */
        //console.log( $("#project-member-list").left);

        //$target.css("left", left + "px")
        //if ($target.is(':hidden')) {
        if (task_open == 0 ){
            var now_width = $target.find(".modal-dialog").width();
            var left = $(document).width() - now_width;
            if ($target.parents(".rightSide").length > 0) {
                var left = $target.parents(".rightSide").width() - now_width;
            }
            $target.css("left", $(document).width() + "px");
            $target.css("width", now_width + "px");
            $("#task-list-left").hide();
            $("#task-list-right").css("margin-left", "0");
            $target.show();
            $target.animate({left: left, opacity: 'show'}, 400,function(){
                //$("#task_activity_con").activityAutoWidth();
            });
        }

        task_open = 1;
        //$target.find(".modal-dialog").css("margin-left", - now_width / 2 + "px");
        //$target.find('.modal-content').addClass("from-below");
		
		/*任务输入输出*/
		if (typeof(fileNewUploadify) !="undefined"){
			fileNewUploadify(30,120,'file_upload_in','输入文档',1,3,'taskFlag');
			fileNewUploadify(30,120,'file_upload_out','输出文档',0,3,'taskFlag');
			fileNewUploadify(30,120,'file_upload_button','选择文件','',4,'');
		}
    };

    var close = function (_target,falg) {
        $target = $(_target);
        //$target.find("form")[0].reset();
        //$target.find("form").validate().resetForm(true);
        $target.find('.modal-content').removeClass("effeckt-show");
        if ($target.hasClass("modal-task")){
            task_open = 0;
        }
        setTimeout(function () {
            $target.hide();
            $target.find('.modal-content').removeClass("from-below");
            $(document.body).css("margin-right", '0px');
            $("html").removeClass("modal-open");
            $target.find(".modal-backdrop").remove();
        }, 300);
        
    };
    $.fn.extend({
        "modalopen": function () {
            var target = $(this);
            open(target);
        }
    });
    $.fn.extend({
        "modalclose": function () {
            var $this = $(this);
            close($this);
        }
    });
    $.fn.extend({
        "opentask": function () {
            var target = $(this);
            open_task(target);
        }
    });
    $(document).on('click.bs.modal.data-api', '[data-toggle="modal"]', function (e) {
        var $this = $(this);
        $target = $($this.attr("data-target"));
        var url = $this.attr("data-url");
        if (url != undefined && url != ""){
            $.ajax(
                {
                    url:url,
                    cache: false,
                    dataType:"html",
                    success: function(html){
                        $target.html(html);
                        open($target);
                    }
                }
            );
        }else{
            open($target)
        }
    });

    $(document).on('click.bs.modal.data-api', '[data-toggle="modal-task"]', function (e) {
        var $this = $(this);
        $target = $($this.attr("data-target"));
        var url = $this.attr("data-url");
        if (url != undefined && url != ""){
            $.ajax(
                {
                    url:url,
                    cache: false,
                    dataType:"html",
                    success: function(html){
                        $target.html(html);
                        open_task($target);
                    }
                }
            );
        }else{
            open_task($target)
        }
    });

    $(document).on('click.bs.modal.data-api', '.modal-cancel,.modal-close,.panel-modal-close', function (e) {
        $target = $(this).closest(".modal,.panel-modal,.modal-task");
        $("#task-list-left").show();
        $("#task-list-right").css("margin-left","240px");

        //$(this).closest("form")[0].reset();
        //$(this).closest("form").validate().resetForm(true);
        close($target);
    });
    //tab选项卡
    $(document).on("click.bs.tab.data-api", '[data-toggle="tab-panel"]:not(.active)', function (e) {
        var $active = $(this).closest(".tab-navs,.tab-btn").find("li.active");
        $active.removeClass("active");
        var $activeTargt = $($active.attr("target"));
        $activeTargt.removeClass("active");
        var $target = $($(this).attr("target"));
        $(this).addClass("active");
        $target.addClass("active");
    });
     $(document).on('click.bs.tab.data-api','[data-toggle="tab"]', function (e) {
         var data=$(this).attr("data");
         var flg=$(this).hasClass("curders");
         $(this).information('tab',{ 
         	data:data,
         	elem:'task-B-wen-cont'
         	 
         })
    });
      $(document).on('click.bs.radio.data-api','[data-toggle="radio"]', function (e) {
          var val = $(this).val();
          var idf = $(this).attr("data-id1");
          var ids = $(this).attr("data-id2");
         $(this).information('radios',{ 
         	val:val,
         	elem1: idf,
         	elem2: ids
         });
    });

     $(document).on('click','.link_edition_no',function(){ 
     	var bg=$(this).attr("data-on");
     	//console.log(bg);

     	if(bg=="on"){ 
     		$(this).removeAttr("style");
     		$(this).attr("data-on","off");
     	}
     	else{ 
     		$(this).css("background","#f1f1f1");
     		$(this).attr("data-on","on");
     	}


     });

    window.onresize = function () {
        //var wind_h = $(window).height();
        ////console.log(wind_h);
        ////if (wind_h > 834)
        //    $(".modal-backdrop").css("height", wind_h + "px");

    };

    

    $(document).on('click',function(e){ 
       		var ofs=$(e.target).parents().hasClass("Pop_up_box");
       		var ofg=$(e.target).hasClass("Pop_up_box");
       		var osg=$(e.target).hasClass("boxes_cu");
       		if(!osg) {
       			if(ofs || ofg){ 
       			}
       		else{ 
       			$(".Pop_up_box").hide();
       		} 
       		}else{ 
       			$(".Pop_up_box").hide();
       			$(e.target).parent().find(".Pop_up_box").show();
       			$(e.target).removeClass('check');
       		}
       });   

    $(document).on('click','.Pop_ddowm_box li',function(e){
    	//alert("aaa"); 
    	$(this).closest('.Pop_up_box').hide();
    });

    $(document).on('click','.Pop_ddowm_box a',function(e){
        //alert("aaa");
        $(this).closest('.Pop_up_box').hide();
    });

    $(document).on('click','.Empty',function(e){
    	//alert("aaa"); 
    	$(this).closest('.modal').find("input:text").val("");
    	$(this).closest('.modal').find("span").css("display","none");
    	$(this).closest('.modal').find("li").removeAttr("style");
    });

}(jQuery);